﻿using DataCenter.Entitys;
using DataCenter.IRepository;
using System.Xml.Linq;

namespace DataCenter.MemoryRepository
{
    public class CustomerRepository : ICustomerRepository
    {
        private static List<Customer> _customers = new List<Customer>()
        {
            new Customer(){ Id=Guid.Parse("50df1479-8f64-e96a-8597-3cf4ab5e4fd1"), Name="神雕", AppName="DataCenter.SystemProvider.dll"},
            new Customer() { Id = Guid.Parse("ccb12173-10a9-8073-6c09-a478cb604177"), Name = "射雕英雄传", AppName = "DataCenter.SystemProvider.dll"},
               new Customer() { Id = Guid.Parse("70c92219-a484-1614-76ad-bdc2dbacf9af"), Name = "天龙八部", AppName = "DataCanter.VipProvider.dll"}
    };
        public async Task<int> Add(Customer customer)
        {
            _customers.Add(customer);
           return await Task.FromResult(1);
        }

        public async Task<int> DeleteById(Guid id)
        {
             var  delItme= _customers.FirstOrDefault(item => item.Id == id);
            _customers.Remove(delItme);
            return await Task.FromResult(1);
        }

        public async Task<IEnumerable<Customer>> GetAll()
        {
          return await  Task.FromResult(_customers);
        }

        public async Task<Customer> GetById(Guid id)
        {
            return await Task.FromResult(_customers.FirstOrDefault(item => item.Id == id));
        }

        public async Task<int> Update(Customer customer)
        {
            var delItme =   _customers.FirstOrDefault(item => item.Id == customer.Id);
            _customers.Remove(delItme);
            _customers.Add(customer);
            return await Task.FromResult(1);
        }
    }
}
